//
//  LYResetPwdViewController.m
//  artist
//
//  Created by Jay_Apple on 16/5/23.
//  Copyright © 2016年 viviyoo. All rights reserved.
//

#import "LYResetPwdViewController.h"
#import "NSString+textCheck.h"

@interface LYResetPwdViewController ()
@property (weak, nonatomic) IBOutlet UITextField *oldPwd;
@property (weak, nonatomic) IBOutlet UITextField *NewPwd;
@property (weak, nonatomic) IBOutlet UITextField *confirmPwd;



@end

@implementation LYResetPwdViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


- (void)updatePwd{

    [LYRequestTool updateUserPwdWithToken:LYToken old_pwd:self.oldPwd.text newPwd:self.NewPwd.text success:^{
        
        [MBProgressHUD showSuccess:@"修改成功"];
        [self.navigationController popViewControllerAnimated:YES];
        
    } failure:^(NSString *code, NSString *message) {
       
        [MBProgressHUD showError:message];
        
    }];

}

- (IBAction)commit:(id)sender {
    
    //是否为空
    if (self.oldPwd.text.length == 0) {
        [MBProgressHUD showOnlyText:@"请输入原密码"];
        return;
    }
    
    if (self.NewPwd.text.length == 0) {
        [MBProgressHUD showOnlyText:@"请输入新密码"];
        return;
    }
    
    if (self.confirmPwd.text.length == 0) {
        [MBProgressHUD showOnlyText:@"请确认新密码"];
        return;
    }
    
    //新旧是否一致
    if (![self.NewPwd.text isEqualToString:self.confirmPwd.text]) {
        [MBProgressHUD showOnlyText:@"新密码确认不一致"];
        return;
    }
    
    //文本校验
    if (![self.NewPwd.text checkPassword]) {
        [MBProgressHUD showOnlyText:@"请输入正确格式密码"];
        return;
    }
    
    //重置密码
    [self updatePwd];
    
}




@end
